<!DOCTYPE html>
<html lang="">
  <head>
    
<meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>


<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />

<meta name="theme-color" content="#f8f5ec" />
<meta name="msapplication-navbutton-color" content="#f8f5ec">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="#f8f5ec">



  <meta name="description" content="目前市面上的版本控制工具，主要为集中式版本控制工具（以SVN为代表）和分布式版本控制工具（当然是git了）。集中式：一个中央服务器控制所有的版本管理，如果中央服务器因为各种原因被毁，那么整个项目的版本控制就完蛋了。而且，不论是提交还是更新，都需要不段的跟服务器进行通信，没有网络就完蛋。容灾性差，通信频繁。分布式：终端可以获取中央服务器的完整信息，就像做了一个完成的镜像。git操作可以全部发生在本地，只需要最终完成后提交服务器就好了，不需要频繁的通信。"/>




  <meta name="keywords" content="整理, ZOE码坊" />










  <link rel="alternate" href="/blog/default" title="ZOE码坊">




  <link rel="shortcut icon" type="image/x-icon" href="/blog/favicon.ico?v=2.9.0" />



<link rel="canonical" href="https://luys.gitee.io/blog/2018/09/02/Android工作学习收集整理（六月）/"/>



  <link rel="stylesheet" type="text/css" href="/blog/lib/fancybox/jquery.fancybox.css" />




  <link rel="stylesheet" type="text/css" href="/blog/lib/nprogress/nprogress.min.css" />



<link rel="stylesheet" type="text/css" href="/blog/css/style.css?v=2.9.0" />



  



  <script id="baidu_push">
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>





  <script src="//cdn1.lncld.net/static/js/3.1.1/av-min.js"></script>
  <script id="leancloud">
    AV.init({
      appId: "kdb8x3rBNollDwJ8ulzKQPb3-gzGzoHsz",
      appKey: "dRlqoI7xVfUXI5urx5r6uOYC"
    });
  </script>




<script>
  window.config = {"title":"ZOE码坊","subtitle":null,"description":null,"author":"Sam Lu","language":null,"timezone":null,"url":"https://luys.gitee.io/blog","root":"/blog/","permalink":":year/:month/:day/:title/","permalink_defaults":null,"source_dir":"source","public_dir":"public/blog","tag_dir":"tags","archive_dir":"archives","category_dir":"categories","code_dir":"downloads/code","i18n_dir":":lang","skip_render":null,"new_post_name":":title.md","default_layout":"post","titlecase":false,"external_link":true,"filename_case":0,"render_drafts":false,"post_asset_folder":false,"relative_link":false,"future":true,"highlight":{"enable":true,"auto_detect":false,"line_number":true,"tab_replace":null},"default_category":"uncategorized","category_map":null,"tag_map":null,"date_format":"YYYY-MM-DD","time_format":"HH:mm:ss","per_page":10,"pagination_dir":"page","theme":"even","deploy":{"type":"git","repo":"https://gitee.com/luys/blog.git","branch":"master"},"ignore":[],"keywords":null,"index_generator":{"per_page":10,"order_by":"-date","path":""},"category_generator":{"per_page":10},"tag_generator":{"per_page":10},"archive_generator":{"per_page":10,"yearly":true,"monthly":true,"daily":false},"marked":{"gfm":true,"pedantic":false,"sanitize":false,"tables":true,"breaks":true,"smartLists":true,"smartypants":true,"modifyAnchors":"","autolink":true},"server":{"port":4000,"log":false,"compress":false,"header":true},"since":2015,"favicon":"/favicon.ico","rss":"default","menu":{"Home":"/","Tags":"/tags","Categories":"/categories"},"color":"Cobalt Blue","toc":true,"fancybox":true,"pjax":true,"copyright":{"enable":true,"license":"<a rel=\"license\" href=\"http://creativecommons.org/licenses/by-nc/4.0/\" target=\"_blank\">知识共享署名-非商业性使用 4.0 国际许可协议</a>"},"reward":{"enable":false,"qrCode":{"wechat":null,"alipay":null}},"social":{"email":"ltym_lys@126.com","stack-overflow":null,"twitter":null,"facebook":null,"linkedin":null,"google":null,"github":"https://github.com/ltym2016","weibo":null,"zhihu":null,"douban":null,"pocket":null,"tumblr":null,"instagram":null},"leancloud":{"app_id":"kdb8x3rBNollDwJ8ulzKQPb3-gzGzoHsz","app_key":"dRlqoI7xVfUXI5urx5r6uOYC"},"baidu_analytics":null,"baidu_verification":null,"google_analytics":null,"google_verification":null,"disqus_shortname":null,"changyan":{"appid":null,"appkey":null},"livere_datauid":null,"version":"2.9.0"};
</script>

    <title> Android工作学习收集整理（六月） - ZOE码坊 </title>
  </head>

  <body><div id="mobile-navbar" class="mobile-navbar">
  <div class="mobile-header-logo">
    <a href="/blog/." class="logo">ZOE码坊</a>
  </div>
  <div class="mobile-navbar-icon">
    <span></span>
    <span></span>
    <span></span>
  </div>
</div>

<nav id="mobile-menu" class="mobile-menu slideout-menu">
  <ul class="mobile-menu-list">
    
      <a href="/blog/">
        <li class="mobile-menu-item">
          
          
            首页
          
        </li>
      </a>
    
      <a href="/blog/tags">
        <li class="mobile-menu-item">
          
          
            标签
          
        </li>
      </a>
    
      <a href="/blog/categories">
        <li class="mobile-menu-item">
          
          
            分类
          
        </li>
      </a>
    
  </ul>
</nav>

    <div class="container" id="mobile-panel">
      <header id="header" class="header"><div class="logo-wrapper">
  <a href="/blog/." class="logo">ZOE码坊</a>
</div>

<nav class="site-navbar">
  
    <ul id="menu" class="menu">
      
        <li class="menu-item">
          <a class="menu-item-link" href="/blog/">
            
            
              首页
            
          </a>
        </li>
      
        <li class="menu-item">
          <a class="menu-item-link" href="/blog/tags">
            
            
              标签
            
          </a>
        </li>
      
        <li class="menu-item">
          <a class="menu-item-link" href="/blog/categories">
            
            
              分类
            
          </a>
        </li>
      
    </ul>
  
</nav>

      </header>

      <main id="main" class="main">
        <div class="content-wrapper">
          <div id="content" class="content">
            
  
  <article class="post">
    <header class="post-header">
      <h1 class="post-title">
        
          Android工作学习收集整理（六月）
        
      </h1>

      <div class="post-meta">
        <span class="post-time">
          2018-09-02
        </span>
        
          <div class="post-category">
            
              <a href="/blog/categories/月度整理/">月度整理</a>
            
          </div>
        
        
        <div class="post-visits"
             data-url="/blog/2018/09/02/Android工作学习收集整理（六月）/"
             data-title="Android工作学习收集整理（六月）">
            阅读次数 0
          </div>
        
      </div>
    </header>

    
    


    <div class="post-content">
      
        <ul>
<li>目前市面上的版本控制工具，主要为集中式版本控制工具（以SVN为代表）和分布式版本控制工具（当然是git了）。<ul>
<li>集中式：一个中央服务器控制所有的版本管理，如果中央服务器因为各种原因被毁，那么整个项目的版本控制就完蛋了。而且，不论是提交还是更新，都需要不段的跟服务器进行通信，没有网络就完蛋。容灾性差，通信频繁。</li>
<li>分布式：终端可以获取中央服务器的完整信息，就像做了一个完成的镜像。git操作可以全部发生在本地，只需要最终完成后提交服务器就好了，不需要频繁的通信。</li>
</ul>
</li>
<li><p>自定义环形统计view</p>
<blockquote>
<p>开始用drawArc根据角度绘制圆环，因为设计图上每两个统计区域有一小段白色间隔，如果圆环的厚度小的话看不出来，当达到一定的厚度，间隔的角度也就出来了，给人感觉不好，后来只好换成drawpath画内圆和外圆覆盖实现，效果不错。</p>
</blockquote>
</li>
<li><p>两个EditText相互监听（TextWatcher），会造成死循环。解决办法：添加标志位控制，标志是否被编辑。</p>
</li>
<li><a href="https://blog.csdn.net/guolin_blog/article/details/51271369" target="_blank" rel="noopener">instant run</a><ul>
<li>增加编译调试的速度</li>
<li>开启该功能后，AndroidStudio将以插件补丁的形式更新app，也就是说，只将程序修改的地方部署到手机上。</li>
<li>hot swap:修改代码方法里的东西，一般指是某个方法里修改了。</li>
<li>warm swap:修改或删除资源文件。</li>
<li>cold swap:比较慢，一般是修改比较多的内容，打包成新的dex文件发送手机上。</li>
<li>Android Studio会根据代码的修改情况自动选择使用哪种swap类型</li>
</ul>
</li>
<li>Android TextView.Html.fromHtml() “span”标签不支持。<blockquote>
<p><a href="https://blog.csdn.net/luckily01/article/details/7714362" target="_blank" rel="noopener">Android TextView 支持的HTML标签</a></p>
</blockquote>
</li>
<li>百度地图开发过程中，发现不同的电脑，同一个项目，跑出的sha1不一样。</li>
<li><p>drawText 可以计算内容的宽度:用Rect计算宽度</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">Rect bounds = new Rect(); </span><br><span class="line">mbPaint.getTextBounds(textString, 0, textString.length(), bounds);</span><br><span class="line">textWidth = bounds.right-bounds.left;</span><br></pre></td></tr></table></figure>
</li>
<li><p>百度地图开发中遇到这样一个问题：Fragment1中有地图，Fragment2中也有地图，从fragment1中跳到fragment2中，这是会出现fragment1中的地图覆盖在fragment2中的地图上，且没有点击和触摸事件。</p>
<ul>
<li>这个压盖问题，是系统GLSurfaceView本身的问题，用两个GLSurfaceView实验也是这样</li>
<li><a href="https://blog.csdn.net/xzytl60937234/article/details/52886048" target="_blank" rel="noopener">解决方案:</a>百度地图新增了TextureMapView可以解决，这是android4.0以上给的解决方案，最好的话开启硬件加速的权限，否则用户切换过快的话，可能会出现一些问题。TextureMapView还可以解决MapView在滑动过程中出现黑边的问题。</li>
</ul>
</li>
<li>ScrollView的滚动监听事件不适用于低版本api（低于23），使用自定义View继承自ScrollView，重写onScrollChanged方法，通过接口将参数传出去。</li>
<li>在PC版本的QQ上可能只看到一条连接，因为PC版本的QQ只会对其白名单的连接作截图，如果不在此名单中，则只是显示连接而已。</li>
<li><p>UserAgent</p>
<ul>
<li>用户代理，是Http协议中的一部分，属于头域的组成部分，User Agent也简称UA</li>
<li>通过这个标识，用户所访问的网站可以显示不同的排版从而为用户提供更好的体验或者信息统计。例如用手机访问谷歌和电脑访问是不一样的，这些就是谷歌根据访问者的UA来判断的。</li>
<li>Android对webview的User-Agent设置：正常是系统UA+自定义的一些相关信息<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">WebSettings settings = webview.getSettings(); </span><br><span class="line">//添加UA,  “app/XXX”：是与h5商量好的标识，h5确认UA为app/XXX就认为该请求的终端为App    </span><br><span class="line">settings.setUserAgentString(settings.getUserAgentString()+&quot;app/XXX&quot;);</span><br><span class="line">settings.setJavaScriptEnabled(true);    </span><br><span class="line">//设置参数    </span><br><span class="line">settings.setBuiltInZoomControls(true);    </span><br><span class="line">settings.setAppCacheEnabled(true);// 设置缓存    </span><br><span class="line">webview.setWebChromeClient(new WebChromeClient());    </span><br><span class="line">webview.loadUrl(loadurl);</span><br></pre></td></tr></table></figure>
</li>
</ul>
</li>
<li><p>Fragmentation框架中，WebView 按返回键 变空白？</p>
<ul>
<li>fragment返回的时候，onDestroy里先调用了Webview的onDestroy方法，webview已经被销毁，此时退出动画还没有结束，webview已经destory了，所以会出现白屏。</li>
<li>解决办法：换成WebviewActivity</li>
<li>换成Activity也不行，相当于新建了一个Fragment栈，这个时候启动原来的栈内fragment只会在MainActivity的那个栈内启动，最后结果就是Fragment在WebviewActivity下面。</li>
<li>只有等退出动画结束才去销毁webview 或者 移除退出动画。</li>
<li>移除退出动画效果也不理想，还是会闪一下白屏。</li>
<li>最终解决办法：监听动画退出<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">@Override</span><br><span class="line">  public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) &#123;</span><br><span class="line">      Animation animation = super.onCreateAnimation(transit, enter, nextAnim);</span><br><span class="line">      animation.setAnimationListener(new Animation.AnimationListener() &#123;</span><br><span class="line">          @Override</span><br><span class="line">          public void onAnimationStart(Animation animation) &#123;</span><br><span class="line">          &#125;</span><br><span class="line">  </span><br><span class="line">          @Override</span><br><span class="line">          public void onAnimationEnd(Animation animation) &#123;</span><br><span class="line">              // 解决直接在onDestroy里销毁webview白屏的问题</span><br><span class="line">              if (isDestroy) &#123;</span><br><span class="line">                  // &#123;...&#125; 销毁webview代码</span><br><span class="line">                  isDestroy = false;</span><br><span class="line">              &#125;</span><br><span class="line">          &#125;</span><br><span class="line">  </span><br><span class="line">          @Override</span><br><span class="line">          public void onAnimationRepeat(Animation animation) &#123;</span><br><span class="line">          &#125;</span><br><span class="line">      &#125;);</span><br><span class="line">      return animation;</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure>
</li>
</ul>
</li>
<li><p>getDimension,getDimensionPixelOffset()和getDimensionPixelSize() 区别， 相同单位下比较，只是返回结果数值不同，其结果只是浮点数，截取的区别</p>
<ul>
<li>getDimension： 返回float</li>
<li>getDimensionPixelOffset：返回的int型，将结果强转成int，小数直接截取，不是四舍五入。</li>
<li>getDimensionPixelSize：返回的int型，将结果强转成int，小数四舍五入。</li>
</ul>
</li>
<li><p>今日头条技术团队 <a href="https://mp.weixin.qq.com/s/d9QCoBP6kV9VSWvVldVVwA" target="_blank" rel="noopener">一种极低成本的Android屏幕适配方式</a></p>
<blockquote>
<p> 关于带有EditText的popupWindow总结。</p>
</blockquote>
<ul>
<li>首先是在Android7.0上面，显示异常问题，在Android7.0上设置popupwindow在某个View下面弹出，结果却跑到了最顶端。解决这个问题比较常见的两个方法。<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">// 方法一：这个方法正常显示没有问题，如果里面含有Edittext，弹出软键盘就不行了，你会发现弹出软键盘的时候，还是将Popupwindow顶到最上面。这个时候就需要第二种解决办法</span><br><span class="line">Rect rect = new Rect();</span><br><span class="line">anchor.getGlobalVisibleRect(rect);</span><br><span class="line">mHeight = anchor.getResources().getDisplayMetrics().heightPixels - rect.bottom;</span><br><span class="line">setHeight(mHeight);</span><br><span class="line">super.showAsDropDown(anchor);</span><br><span class="line">//方法二：这个针对Android 7.0 api24进行处理，代码如下</span><br><span class="line">int[] a = new int[2];</span><br><span class="line">anchor.getLocationInWindow(a);</span><br><span class="line">// 算上点击View的高度才行</span><br><span class="line">int heignt = anchor.getHeight();</span><br><span class="line">this.showAtLocation(mActivity.getWindow().getDecorView(), Gravity.NO_GRAVITY, 0, a[1]+heignt);</span><br><span class="line">this.update();</span><br></pre></td></tr></table></figure>
</li>
</ul>
</li>
<li><p>弹出软键盘遮挡EditText的问题，开始根据网上资料设置</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);</span><br><span class="line">setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);</span><br></pre></td></tr></table></figure>
<p>发现并没有乱用，最终解决办法还是监听软键盘的弹出设置底部EditText的topMargin。当然这里要使用popupwindow的update动态改变popupwindow的高度。这里要计算好topmargin的高度。</p>
<ul>
<li>关于PopupWindow弹出背景变半透明。网上一大堆文章都是说弹出Popupwindow让整个背景都半透明，这样体验很差，我只需要下拉的时候，下面半透明就好了。这里的解决办法是让整个Popupwindow的高度充满屏幕。最外层布局是个FrameLayout，宽高都是match_parent，背景为半透明，然后popupwindow的具体内容addView进去。设置poupwindow进入动画的同时设置frameLayout的背景透明度从0f到1f。</li>
<li>这个时候你会发现点击下面半透明popupwindow并没有消失，这是因为你点击的还是Popupwindow，这个时候我们可以添加一个透明View在下面，然后监听透明View的点击事件就可以了。</li>
</ul>
</li>
</ul>

      
    </div>

    
      
      

  <div class="post-copyright">
    <p class="copyright-item">
      <span>原文作者: </span>
      <a href="https://luys.gitee.io/blog">Sam Lu</a>
    </p>
    <p class="copyright-item">
      <span>原文链接: </span>
      <a href="https://luys.gitee.io/blog/2018/09/02/Android工作学习收集整理（六月）/">https://luys.gitee.io/blog/2018/09/02/Android工作学习收集整理（六月）/</a>
    </p>
    <p class="copyright-item">
      <span>许可协议: </span>
      
      <a rel="license" href="http://creativecommons.org/licenses/by-nc/4.0/" target="_blank">知识共享署名-非商业性使用 4.0 国际许可协议</a>
    </p>
  </div>



      
      
    

    
      <footer class="post-footer">
        
          <div class="post-tags">
            
              <a href="/blog/tags/整理/">整理</a>
            
          </div>
        
        
        
  <nav class="post-nav">
    
      <a class="prev" href="/blog/2018/09/02/Android工作学习收集整理（七月）/">
        <i class="iconfont icon-left"></i>
        <span class="prev-text nav-default">Android工作学习收集整理（七月）</span>
        <span class="prev-text nav-mobile">上一篇</span>
      </a>
    
    
      <a class="next" href="/blog/2018/09/02/Android工作学习收集整理（五月）/">
        <span class="next-text nav-default">Android工作学习收集整理（五月）</span>
        <span class="prev-text nav-mobile">下一篇</span>
        <i class="iconfont icon-right"></i>
      </a>
    
  </nav>

      </footer>
    

  </article>


          </div>
          
  <div class="comments" id="comments">
    
  </div>


        </div>
      </main>

      <footer id="footer" class="footer">

  <div class="social-links">
    
      
        
          <a href="mailto:ltym_lys@126.com" class="iconfont icon-email" title="email"></a>
        
      
    
      
    
      
    
      
    
      
    
      
    
      
        
          <a href="https://github.com/ltym2016" class="iconfont icon-github" title="github"></a>
        
      
    
      
    
      
    
      
    
      
    
      
    
      
    
    
    
      
      <a href="/blog/atom.xml" class="iconfont icon-rss" title="rss"></a>
    
  </div>


<div class="copyright">
  <span class="power-by">
    由 <a class="hexo-link" href="https://hexo.io/">Hexo</a> 强力驱动
  </span>
  <span class="division">|</span>
  <span class="theme-info">
    主题 - 
    <a class="theme-link" href="https://github.com/ahonn/hexo-theme-even">Even</a>
  </span>

  <span class="copyright-year">
    
    &copy; 
     
      2015 - 
    
    2018

    <span class="heart">
      <i class="iconfont icon-heart"></i>
    </span>
    <span class="author">Sam Lu</span>
  </span>
</div>

      </footer>

      <div class="back-to-top" id="back-to-top">
        <i class="iconfont icon-up"></i>
      </div>
    </div>

    
  
  

  



    
  



  
  





  
    <script type="text/javascript" src="/blog/lib/jquery/jquery.min.js"></script>
  

  
    <script type="text/javascript" src="/blog/lib/slideout/slideout.js"></script>
  

  
    <script type="text/javascript" src="/blog/lib/fancybox/jquery.fancybox.pack.js"></script>
  

  
    <script type="text/javascript" src="/blog/lib/pjax/jquery.pjax.min.js"></script>
  

  
    <script type="text/javascript" src="/blog/lib/nprogress/nprogress.min.js"></script>
  


    <script type="text/javascript" src="/blog/js/src/even.js?v=2.9.0"></script>

  </body>
</html>
